/**
 * Created by kule on 2017/5/17.
 */
import filter from 'lodash/filter';
import pickBy from 'lodash/pickBy';
import findIndex from 'lodash/findIndex';
import isFunction from 'lodash/isFunction';

const flag={};
export const conditionArray=(array)=>{
    return filter(array,(item)=>{
        return !(item===flag);
    });
};
export const conditionObject=(object)=>{
    return pickBy(object,(item)=>{
        return !(item===flag);
    });
};
export const condition=(val,...conditions)=>{
    const falseIndex=findIndex(conditions,(cond)=>{
        if(isFunction(cond)){
            return !cond(val);
        }
        return !cond;
    });
    return falseIndex>-1?flag:val;
};